//
//  RTTabBar.m
//  WeiboSina
//
//  Created by Brisinga on 16/3/4.
//  Copyright © 2016年 Root. All rights reserved.
//

#import "RTTabBar.h"


@interface RTTabBar ()

@property (nonatomic, strong) UIButton *composeButton;

@end

@implementation RTTabBar



#pragma mark - 布局子控件
- (void)layoutSubviews {
    [super layoutSubviews];
   
    // 设置composeButton的位置
    self.composeButton.center = CGPointMake(self.width * 0.5, self.height * 0.5);
    
    // 设置其他icon的位置
    CGFloat width = self.width * 0.2;
    
    
   __block NSInteger index = 0;
    
    [self.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        if ([obj isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            
            obj.x = index * width;
            
            obj.width = width;
            index++;
            
            if (index==2) {
                
                index ++;
            }
        }
    }];
}


#pragma mark - composeButton点击事件
- (void)composeButtonDidClick:(UIButton *)sender {
    
    NSLog(@"按钮点击");
    
    self.composeBtnClick();
}


#pragma mark - 懒加载composeButton
- (UIButton *)composeButton {
    
    if (nil==_composeButton) {
        
        _composeButton = [[UIButton alloc] init];
        
        [_composeButton addTarget:self action:@selector(composeButtonDidClick:) forControlEvents:UIControlEventTouchUpInside];
        
        [_composeButton setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
        
        [_composeButton setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
        
        [_composeButton setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
        
        [_composeButton setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
        
        [_composeButton sizeToFit];
        
        [self addSubview:_composeButton];
    }
    
    return _composeButton;
    
}

@end
